import Vue from 'vue'
import VueRouter from 'vue-router'
import api from "./api"

Vue.use(VueRouter)
var paths = [];
for (let string of api) {
    if(string.indexOf("$") === 0){
        var str = string.substring(1);
        var i = str.indexOf(":");
        str = str.substring(0, i);
        paths.push({
            path: str,
            name: str,
            component: () => import(`../components/${str}.vue`)
        })
    } else {
        paths.push({
            path: string,
            name: string,
            component: () => import("../components/Doc.vue")
        })
    }
}

const routes = [
    {
        path: "/",
        redirect: "/checkLogin"
    },
    {
        path: "/checkLogin",
        component: () => import("../views/Home.vue")
    },
    {
        path: "/index",
        component: () => import("../views/Index.vue")
    },
    {
        path: "/convert",
        component: () => import("../views/Convert.vue")
    },
    {
        path: "/menu",
        component: () => import("../views/Menu.vue")
    },
    {
        path: "/workBench",
        component: () => import("../views/WorkBench.vue")
    },
    {
        path: "/dep/:id",
        component: () => import("../views/Dep.vue")
    },
    {
        path: "/role/:id",
        component: () => import("../views/Role.vue")
    },
    {
        path: "/login",
        component: () => import("../views/Login.vue")
    },
    {
        path: "/formDesign",
        component: () => import("../views/FormDesign.vue")
    },
    {
        path: "/bpmDesign"   ,
        component: () => import("../views/BpmDesign.vue")
    },
    {
        path: "/mqtest"   ,
        component: () => import("../views/MQTest.vue")
    },
    {
        path: '/doc',
        name: 'main',
        component: () => import("../views/Doc.vue"),
        children: [
            {
                path: '/',
                redirect: paths[1].name,
            },
            ...paths
            // {
            //   path: 'userTable',
            //   name:"userTable",
            //   component: () => import("../views/userTable.vue"),
            // },
            // {
            //   path: 'edit',
            //   name:'userEdit',
            //   component: () => import("../views/userEdit.vue"),
            // },
            // {
            //   path: 'import',
            //   component: () => import("../views/userImport.vue"),
            // }
        ]
    },
    {
        path: '/user/:type',
        // name: 'user',
        component: () => import("../views/user/User.vue"),
        children:[
            {
                path: '/',
                redirect:"search",
            },
            {
                path: 'search',
                component: () => import("../views/user/userSearch.vue"),
            },
            {
                path: 'userTable',
                name:"userTable",
                component: () => import("../views/user/userTable.vue"),
            },
            {
                path: 'edit',
                name:'userEdit',
                component: () => import("../views/user/userEdit.vue"),
            },
            {
                path: 'import',
                component: () => import("../views/user/userImport.vue"),
            }
        ]
    },
    // 用户
    {
        path: '/userSetting',
        name: 'userSetting',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/UserSetting.vue'),
    },
    {
        path: '/userInfo',
        name: 'userInfo',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/userInfo.vue'),
    },,
    {
        path: '/menuAuthority',
        name: 'menuAuthority',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/MenuAuthority.vue'),
    },
    /*
    收件箱
  */
    {
        path: '/message/:type',
        name: 'message',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/message/index.vue'),
        children:[
            {
                path: '/',
                redirect:"inbox",
            },
            {
                path: 'inbox',
                component: () => import("../views/message/inbox.vue"),
                meta: {
                    keepAlive: true // 需要被缓存
                }
            },
            {
                path: 'view',
                component: () => import("../views/message/view.vue"),
                meta: {
                    keepAlive: false // 需要被缓存
                }
            },
            {
                path: 'send',
                component: () => import("../views/message/send.vue"),
                meta: {
                    keepAlive: false // 需要被缓存
                }
            },
        ]
    },

];
console.log(routes)

const router = new VueRouter({
    routes
})

export default router
